import { store } from "@/store";
import LogoImg from "@/assets/logo.png";
import UserAPI from "@/api/system/user.api";

export const useLogoStore = defineStore("logo", () => {
  const LogoInfo = useStorage("LogoInfo", { logo_title: "", logo_img: "" });

  const getLogoInfo = async () => {
    // 发送请求获取logo信息
    let logoInfo = await UserAPI.getLogoInfo();
    logoInfo.logo_img = logoInfo.logo_img.indexOf("uploads") === -1 ? LogoImg : logoInfo.logo_img;
    logoInfo.logo_title = logoInfo.logo_title || "默认logo";
    LogoInfo.value = logoInfo;
  };

  return {
    LogoInfo,
    getLogoInfo,
  };
});


// 用于在组件外部（如在Pinia Store 中）使用 Pinia 提供的 store 实例。

export function useLogoStoreHook() {
  return useLogoStore(store);
}
